import '../../../public.dart';

/// 章节服务类
///
class ReaderChapterService {
  ReaderChapterService();

  /// 获取章节数据
  Future<List<dynamic>> getChapterData(int comicId, int chapterId) async {
    List<dynamic> re = await ACGN.http.fetch(
        ACGN.config.interfaceApi.getchapterdata,
        queryParameters: {
          'comic_id': comicId,
          'chapter_id': chapterId,
          'quality': 'middle'
        },
        isParse: false);
    return re;
  }

  /// 提交阅读记录
  Future<void> addUserRead(ChapterModel chapter, int pageIndex, int uid) async {
    ACGN.http.fetch(ACGN.config.interfaceApi.adduserread,
        method: HttpMethodType.POST,
        data: {
          'myuid': uid,
          'comic_id': chapter.comicModel.id,
          'chapter_id': chapter.id,
          'chapter_name': chapter.name,
          'chapter_page': pageIndex
        });
  }

  /// 收藏漫画
  Future<void> addUserCollect(
      ChapterModel chapter, int uid, String action) async {
    ACGN.http.fetch(ACGN.config.interfaceApi.setusercollect,
        method: HttpMethodType.POST,
        data: {
          'myuid': uid,
          'comic_id': chapter.comicModel.id,
          'action': action
        });
  }
}
